package designpattern.structural_patterns;

public class StatePattern {

	public class Context{
		State state;

		public State getState() {
			return state;
		}

		public void setState(State state) {
			this.state = state;
		}
		public void request(){
			this.state.handle(this);
		}
	}
	
	interface State{
		void handle(Context context);
	}
	public class ConcreteStateA implements State{
		@Override
		public void handle(Context context) {
			System.out.print("ConcreteStateA\n");
			context.setState(new ConcreteStateB());
		}
	}
	public class ConcreteStateB implements State{
		@Override
		public void handle(Context context) {
			System.out.print("ConcreteStateB\n");
			context.setState(new ConcreteStateA());
		}
	}
	
	public static void main(String[] args) {
		StatePattern pattern = new StatePattern();
		Context context = pattern.new Context();
		context.setState(pattern.new ConcreteStateA());
		//
		context.request();
		context.request();
		context.request();
		context.request();
		context.request();
	}

}
